<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>企业人员情况展示
            <small>人员概况</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>工作台</el-breadcrumb-item>
            <el-breadcrumb-item>企业人员概况</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="姓名/手机号" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="companyName" label="企业名称" align="center"></el-table-column>
                <el-table-column prop="name" label="员工姓名" align="center"></el-table-column>
                <el-table-column label="目前状况" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.currentStatus == '2' ? '有不良症状(发烧，呼吸困难等)' : '良好'}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="性别" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="teardownTime" label="预计反宁时间" align="center"></el-table-column>
                <el-table-column prop="currentAddr" label="现居住地" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="联系电话" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>

            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增人员概况" :visible.sync="dialogFormVisible">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="企业名称" prop="companyName">
                                    <el-input v-model="formData.companyName"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="姓名" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="性别">
                                    <el-select v-model="formData.sex">
                                        <el-option label="不限" value="0"></el-option>
                                        <el-option label="男" value="1"></el-option>
                                        <el-option label="女" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="年龄">
                                    <el-input v-model="formData.age"/>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="籍贯" prop="origo">
                                    <el-input v-model="formData.origo"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="现居住地" prop="currentAddr">
                                    <el-input v-model="formData.currentAddr"/>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="是否来宁">
                                    <el-select v-model="formData.ning">
                                        <el-option label="是" value="1"></el-option>
                                        <el-option label="否" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="是否接触湖北人员">
                                    <el-select v-model="formData.contactWh">
                                        <el-option label="是" value="1"></el-option>
                                        <el-option label="否" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="是否接触浙江温州人员">
                                    <el-select v-model="formData.contactWz">
                                        <el-option label="是" value="1"></el-option>
                                        <el-option label="否" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="目前症状">
                                    <el-select v-model="formData.currentStatus">
                                        <el-option label="良好" value="1"></el-option>
                                        <el-option label="有不良症状(发烧，呼吸困难等)" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="身份证号码" prop="idCard">
                                    <el-input v-model="formData.idCard"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="手机号" prop="phoneNumber">
                                    <el-input v-model="formData.phoneNumber"/>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="48">
                                <el-form-item label="本人承诺对本次调查的真实性负责">
                                    <el-select v-model="formData.responsible">
                                        <el-option label="是" value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑检查项" :visible.sync="dialogFormVisible4Edit">
                    <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="项目编码" prop="code">
                                    <el-input v-model="formData.code"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="项目名称" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="性别">
                                    <el-select v-model="formData.sex">
                                        <el-option label="不限" value="0"></el-option>
                                        <el-option label="男" value="1"></el-option>
                                        <el-option label="女" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="适用年龄">
                                    <el-input v-model="formData.age"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="类型">
                                    <el-select v-model="formData.type">
                                        <el-option label="检查" value="1"></el-option>
                                        <el-option label="检验" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="价格">
                                    <el-input v-model="formData.price"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="项目说明">
                                    <el-input v-model="formData.remark" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="注意事项">
                                    <el-input v-model="formData.attention" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            rules: {//校验规则
                code: [{required: true, message: '项目编码为必填项', trigger: 'blur'}],
                name: [{required: true, message: '项目名称为必填项', trigger: 'blur'}]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        //钩子函数，页面加载完成后可以直接展示分页数据
        created() {
            this.findPage();
        },
        methods: {
            //编辑，进入编辑页面，对表单进行校验，当校验通过后发送异步请求，缓存检查项信息！
            handleEdit() {
                this.$refs["dataEditForm"].validate((valid) => {
                    if (valid) {//表单校验通过
                        //发送异步请求
                        axios.post("/checkItem/edit.do", this.formData).then((res) => {
                            //隐藏编辑窗口
                            this.dialogFormVisible4Edit = false;
                            if (res.data.flag) {
                                //编辑成功，给出提示
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                });
                            } else {
                                //编辑保存失败
                                this.message.error(res.data.message);
                            }
                        }).finally(() => {

                        });
                    } else {
                        //表单校验失败
                        this.message.error("表单数据校验失败！");
                        return false;
                    }
                });
            },
            //添加
            /**
             * axios.get('/user',{
                    params:{
                    ID:12345}
                    }).then(function(response){
                    console.log(response);
                    }) .catch(function(err){
                    console.log(err);
                    });
             * */
            handleAdd() {
                // let _this = this;
                this.$refs["dataAddForm"].validate((valid) => {
                    if (valid) {
                        console.log(this.formData);//价格数据显示在浏览器的console窗口处
                        axios.post("/personnelDetails/add.do", this.formData).then((res) => {
                            //关闭新建窗口
                            this.dialogFormVisible = false;
                            if (res.data.flag) {//执行成功
                                //创建成功后重新调用分页查询方法，查询最新数据
                                this.findPage();
                                //弹出提示信息
                                this.$message({
                                    message: res.data.message,
                                    type: "success"
                                });
                            } else {//执行失败
                                //弹出错误提示
                                this.$message.error(res.data.message)
                            }
                        });
                    } else {
                        //校验不通过
                        this.$message.error("数据校验失败，请检查输入的信息是否正确！");
                        //结束方法！
                        return false;
                    }
                });
            },
            //分页查询
            findPage() {
                // let _this = this;
                //分页参数
                let param = {
                    currentPage: this.pagination.currentPage,//页码
                    pageSize: this.pagination.pageSize,//每页显示的记录数
                    queryString: this.pagination.queryString//查询条件
                };
                //异步请求
                axios.post("/personnelDetails/findPage.do", param).then((response) => {
                    //为模型数据赋值，基于VUE的双向数据绑定展示到页面
                    this.dataList = response.data.rows;
                    this.pagination.total = response.data.total;
                });
            },
            // 重置表单,进行数据绑定，表单填写数据后，Vue对象就会将数据更新！每次点击新建时要重置表单！
            resetForm() {
                this.formData = {};
            },
            // 弹出添加窗口,增加窗口默认是不显示的，当点击新建后出发点击事件，将其值设置为true
            handleCreate() {
                this.dialogFormVisible = true;
                //每次点击新建表格时，将formDate进行重置！
                this.resetForm();
            },
            // 弹出编辑窗口-->数据的回显
            handleUpdate(row) {
                //发送异步请求，请求检查项信息（回显数据）
                this.activeName = "first";
                axios.post("/checkItem/findById.do?id=" + row.id).then((res) => {
                    if (res.data.flag) {//代表根据查询到编辑的检查项信息
                        //设置编辑窗口的属性，dialogFormVisible4Edit为true则表示显示
                        this.dialogFormVisible4Edit = true;
                        //数据的属相绑定，将查询到的数据回显到编辑界面
                        this.formData = res.data.data;
                    } else {
                        this.$message.error("获取数据失败，请刷新当前页面！")
                    }
                });
            },
            showMessage(r) {
                if (r == 'Error: Request failed with status code 403') {
                    //权限不足
                    this.$message.error('无访问权限');
                    return;
                } else {
                    this.$message.error('未知错误');
                    return;
                }

            },
            //切换页码
            handleCurrentChange(currentPage) {
                //currentPage为切换后的页码
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 删除
            handleDelete(row) {
                //function()-->回调函数
                this.$confirm("确认删除吗？", "提示", {type: 'warning'}).then(() => {
                    axios.post("/checkItem/delete.do?id=" + row.id).then((res) => {
                        if (!res.data.flag) {
                            //删除失败
                            this.$message.error(res.data.message);
                        } else {
                            //删除成功
                            this.$message({
                                message: res.data.message,
                                type: 'success'
                            });
                            //无论删除成功与否调用分页获取最新数据
                            this.findPage();
                        }
                    }).catch((res) => {
                        this.showMessage(res)
                    });
                });
            }
        }
    })
</script>
</html>